package com.linkage.jz.bankruptcy.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.bean.Vote.ProVoteVoterGroup;

import java.util.List;

public class ProVoteGroupListDialog extends Dialog {

    private final Context mContext;
    private TextView titleText;
    private ListView mListView;
    private LinearLayout operateLayout;
    private List<ProVoteVoterGroup> data;
    private AdapterView.OnItemClickListener clickListener;

    public ProVoteGroupListDialog(Context context, List<ProVoteVoterGroup> list, AdapterView.OnItemClickListener itemClickListener) {
        super(context);
        mContext = context;
        this.clickListener = itemClickListener;
        initView();
        init(list);
        showOperate(false);
    }

    private void initView() {
        View contentView = View.inflate(mContext, R.layout.pro_vote_group_list_dialog, null);
        mListView = contentView.findViewById(R.id.list);
        titleText = contentView.findViewById(R.id.title);
        operateLayout = contentView.findViewById(R.id.layout_operate);
        setContentView(contentView);
        titleText.setText("选择分组");
    }

    private void showOperate(boolean show) {
        operateLayout.setVisibility(show ? View.VISIBLE : View.GONE);
    }

    private void init(List<ProVoteVoterGroup> list) {
        this.data = list;
        ArrayAdapter<String> stringArrayAdapter = new ArrayAdapter<>(mContext, android.R.layout.simple_expandable_list_item_1);
        if(null != data && data.size() > 0) {
            for (ProVoteVoterGroup group : data) {
                stringArrayAdapter.add(group.getName());
            }
        }
        mListView.setAdapter(stringArrayAdapter);
        mListView.setOnItemClickListener(clickListener);
    }
}
